<template>
  <div id="shareTopSearch">
    <h1 class="con-right-title">
      小视频批量维护管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <!-- 输入搜索部分 -->
        <el-form-item label="视频VID" prop="vid">
          <el-input
            v-model="formInline.vid"
            placeholder="请输入视频VID搜索"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="视频创建标题" prop="searchTitle">
          <el-input
            v-model="formInline.searchTitle"
            placeholder="请输入视频创建标题搜索"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="上传视频人" prop="uploadUserId">
          <el-select
            v-model="formInline.uploadUserId"
            filterable
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item, index) in operaPeopleList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="视频状态" prop="state">
          <el-select v-model="formInline.state" placeholder="请选择">
            <el-option
              v-for="item in stateList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="视频上传时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'shareTopSearch',
  msg: '分享语管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          vid: '', // 视频VID
          searchTitle: '', // 标题
          uploadUserId: '', // 上传视频人
          state: '', // 视频状态
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 上传视频人
      operaPeopleList: [{ nickname: '全部', dapengUserId: '' }],
      // 视频状态
      stateList: [],
      rules: {
        vid: {},
        uploadUserId: {},
        searchTitle: {},
        state: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getFilterList()
  },
  methods: {
    /* 获取用户状态 */
    async getFilterList() {
      // 视频状态
      let data = await sysNormalDisable(
        'work_material_statu',
        'workBatchVideoState'
      )
      this.stateList = this.stateList.concat(data)
      // 获取选择运营人员
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.operaPeopleList = this.operaPeopleList.concat(response)
      })
      //设置默认数据
      this.setDefaultValue()
      //触发获取列表
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.state = this.stateList[0].dictValue
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    }
  }
}
</script>

<style lang="less"></style>
